package de.fhtrier.mp.wollmaus.gamestate.menus;

import java.util.ArrayList;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import de.fhtrier.mp.wollmaus.entity.Entity;
import de.fhtrier.mp.wollmaus.util.AssetManager;

public abstract class AbstractSubMenuState {

	protected Image img;
	protected MenuState menu;
	protected ArrayList<Entity> entities;
	
	public AbstractSubMenuState(MenuState menu, int img) {
		this.menu = menu;
		this.img = AssetManager.getInstance().getImage(img);
		entities = new ArrayList<Entity>();
	}
	
	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		if (gc.getInput().isKeyDown(Input.KEY_ENTER)) {
			menu.startGameStart(sbg);
		}
		
		for (Entity e : entities) {
			e.update(gc, delta);
		}
	}
	
	public void render(Graphics g, GameContainer gc) {
		for (Entity e : entities) {
			e.render(g, gc);
		}
	}

	public Image getImage() {
		return img;
	}

	public void button1Pressed(GameContainer gc, StateBasedGame sbg, int delta) {
	}

	public void button2Pressed(GameContainer gc, StateBasedGame sbg, int delta) {
	}

	public void button3Pressed(GameContainer gc, StateBasedGame sbg, int delta) {
	}

	public void button4Pressed(GameContainer gc, StateBasedGame sbg, int delta) {
	}

	public void button5Pressed(GameContainer gc, StateBasedGame sbg, int delta) {
	}

	public void buttonBackPressed(GameContainer gc, StateBasedGame sbg, int delta) {
		menu.setMenuState(new MainState(menu));
	}
	
	public void addEntity(Entity e) {
		entities.add(e);
	}
	
	public void removeEntity(Entity e) {
		entities.remove(e);
	}

}
